export function formatDate(date) {
  const year = date.getFullYear()
  const month = String(date.getMonth() + 1).padStart(2, '0')
  const day = String(date.getDate()).padStart(2, '0')
  const hours = String(date.getHours()).padStart(2, '0')
  const minutes = String(date.getMinutes()).padStart(2, '0')

  return `${year}-${month}-${day} ${hours}:${minutes}`
}

export function formatTime(date) {
  const hours = String(date.getHours()).padStart(2, '0')
  const minutes = String(date.getMinutes()).padStart(2, '0')
  return `${hours}:${minutes}`
}

export function getDateRange(type) {
  const now = new Date()
  const result = {
    start: new Date(),
    end: now
  }

  switch (type) {
    case 'day':
      result.start = new Date(now.setHours(0, 0, 0, 0))
      break
    case 'week':
      result.start = new Date(now.setDate(now.getDate() - 7))
      break
    case 'month':
      result.start = new Date(now.setMonth(now.getMonth() - 1))
      break
    default:
      break
  }

  return result
}